import { Body, Controller, Post, Req } from '@nestjs/common';
import { OfficialUserService } from './official-user.service';
import { DtoPipe } from '../../pipe/dto/dto.pipe';
import { ResponseUtilService } from '@app/response-util';
import { OfficialUser } from '@app/db/entity/OfficialUser';
import PageDto from './dto/page.dto';

@Controller('officialUser')
export class OfficialUserController {

    constructor(
        private readonly service:OfficialUserService
    ){}


    @Post('add')
    async add(@Body() dto:OfficialUser, @Req() req) {
        try {
            const r = await this.service.add(dto)
            return r ? ResponseUtilService.successRes() : ResponseUtilService.failRes()
        } catch (error) {
            return ResponseUtilService.failRes(error.message)
        }
    }

    @Post('page')
    async superUserPage(@Body(new DtoPipe({skipMissingProperties : true})) dto:PageDto, @Req() req) {
        const r = await this.service.page(dto)
        return ResponseUtilService.successRes(r)
    }
}
